from fastapi import APIRouter

from core.role_core import create_role_to_core, get_role_by_id, update_role_by_id, delete_role_by_id
from entity.schema.role_schema import RoleCreate
from utils.base_response import BaseResponse

role=APIRouter()




@role.post("/add")
async def create_role(role: RoleCreate):
    """
    创建角色
    """

    role=await create_role_to_core(role.name,role.desc)
    return BaseResponse(code=200, message="创建成功", data=None)




@role.get("/get/{role_id}")
async def get_role(role_id: int):
    """
    获取角色
    """
    role=await get_role_by_id(role_id)
    return BaseResponse(code=200, message="获取成功", data=role)

@role.put("/update/{role_id}")
async def update_role(role_id: int, role: RoleCreate):
    """
    更新角色
    """
    role=await update_role_by_id(role_id,role)
    return BaseResponse(code=200, message="更新成功", data=None)

@role.delete("/delete/{role_id}")
async def delete_role(role_id: int):
    """
    删除角色
    """
    role=await delete_role_by_id(id=role_id)
    return BaseResponse(code=200, message="删除成功", data=None)